package com.zhuiyun.educations.api.sysuserback.controller;

import com.zhuiyun.educations.api.sysuserback.entiy.DTO.SysUserBackUpdatePasswordDTO;
import com.zhuiyun.educations.api.sysuserback.entiy.SysUserBack;
import com.zhuiyun.educations.api.sysuserback.entiy.vo.SysUserBackVo;
import com.zhuiyun.educations.api.sysuserback.service.SysUserBackService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.Md5Utils;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.index.IndexValueTransformer;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName SysUserBackController
 * @Description TODO
 * @Author MJL
 * @Date 2023/6/15 15:33
 **/
@RestController
@RequestMapping("/User")
public class SysUserBackController{
    @Autowired
    SysUserBackService sysUserBackService;
    /*/**
    * @Author MJL
    * @Description todo 登录
    * @Date 2023/6/15 15:54
    * @Return  * @param null
    */
    @PostMapping("/login")
    public CommonResult login(@RequestBody SysUserBack sysUserBack){
        CommonResult commonResult = sysUserBackService.login(sysUserBack);
        return commonResult;
    }
    /**
    * @Author MJL
    * @Description todo 用户表全查
    * @Date 2023/6/15 19:33
    * @Return  * @param null
    */
    @GetMapping("/SysUserList")
    public CommonResult userList(SysUserBackVo sysUserBackVo, PageRequest pageRequest){
        return CommonResult.ok(sysUserBackService.userList(sysUserBackVo,pageRequest));
    }
    /**
    * @Author MJL
    * @Description todo 用户表添加
    * @Date 2023/6/16 9:01
    * @Return  * @param null
    */
    @PostMapping("/SysUserAdd")
    public CommonResult SysUserAdd(@RequestBody SysUserBack sysUserBack){
        int i = sysUserBackService.SysUserAdd(sysUserBack);
        if (i>0){
            return CommonResult.ok("恭喜您，添加成功");
        }else {
            return CommonResult.error("很抱歉，添加失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 用户表逻辑删除
    * @Date 2023/6/16 13:45
    * @Return  * @param null
    */
    @DeleteMapping("/SysUserDelete")
    public CommonResult SysUserDelete(Integer id){
        int i = sysUserBackService.SysUserDelete(id);
        if (i>0){
            return CommonResult.ok("恭喜您，删除成功");
        }else {
            return CommonResult.error("很抱歉，删除失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 用户表修改
    * @Date 2023/6/16 14:34
    * @Return  * @param null
    */
    @PutMapping("/SysUserUpdate")
    public CommonResult SysUserUpdate(@RequestBody SysUserBack sysUserBack){
        int i = sysUserBackService.SysUserUpdate(sysUserBack);
        if (i>0){
            return CommonResult.ok("恭喜您，修改成功");
        }else {
            return CommonResult.error("很抱歉，修改失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 用户表修改密码
    * @Date 2023/6/20 8:51
    * @Return  * @param null
    */
    @PostMapping("/SysUserUpdatePassword")
    public CommonResult SysUserUpdatePassword(@RequestBody SysUserBackUpdatePasswordDTO sysUserBackUpdatePasswordDTO){
        Integer i = sysUserBackService.SysUserUpdatePassword(sysUserBackUpdatePasswordDTO);
        if (i>0){
            return CommonResult.ok("恭喜您，更改密码成功");
        }else {
            return CommonResult.error("很抱歉，更改密码失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 根据用户名查询是否重复
    * @Date 2023/6/30 8:55
    * @Return  * @param null
    */
    @GetMapping("/repeatUserLoginName")
    public CommonResult repeatUserLoginName(String userLoginName){
        return sysUserBackService.repeatUserLoginName(userLoginName);
    }
    /**
    * @Author MJL
    * @Description todo 用户表分配角色
    * @Date 2023/7/5 14:28
    * @Return  * @param null
    */
    @PostMapping("/userAssignmentRole")
    public CommonResult userAssignmentRole(@RequestBody SysUserBack sysUserBack) {
        int i = sysUserBackService.userAssignmentRole(sysUserBack);
        if (i>0){
            return CommonResult.ok("恭喜您，权限分配成功！");
        }else {
            return CommonResult.error("很抱歉，权限分配失败");
        }
    }
}